home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / AppleShare IP SDK / ASIP Server Controls⁄Events / Libraries / SyncServerDispatch.c
Encoding:
C/C++ Source or Header  |  1999-05-21  |  4.3 KB  |  140 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Glue to call ServerDispatch from a PowerPC application
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support
  7. **  modified for ASIP 6.0 SDK by Erik Sea
  8. **
  9. **    File:        SyncServerDispatch.c
  10. **
  11. **    Copyright © 1995,1998 Apple Computer, Inc.
  12. **    All rights reserved.
  13. **
  14. **    You may incorporate this sample code into your applications without
  15. **    restriction, though the sample code has been provided "AS IS" and the
  16. **    responsibility for its operation is 100% yours.  However, what you are
  17. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  18. **    after having made changes. If you're going to re-distribute the source,
  19. **    we require that you make it clear in the source that the code was
  20. **    descended from Apple Sample Code, but that you've made changes.
  21. */
  22.  
  23. #include <Types.h>
  24. #include <MixedMode.h>
  25. #include <Errors.h>
  26. #include <Traps.h>
  27.  
  28. #include "AppleShareFileServerControl.h"
  29.  
  30. /*
  31. **    The function calling convention ServerDispatchProc
  32. */
  33. typedef    pascal OSErr (*ServerDispatchProcPtr)(SInt32 dZero, SCParamBlockRec* thePB);
  34.  
  35. typedef UniversalProcPtr ServerDispatchProcUPP;
  36.  
  37. /*
  38. **    Procedure information for ServerDispatchProc function
  39. */
  40. enum
  41. {
  42.     uppServerDispatchProcInfo = kRegisterBased
  43.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(long)))
  44.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(long)))
  45.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA0, SIZE_CODE(sizeof(SCParamBlockRec*)))
  46. };
  47.  
  48. /*
  49. **    The CallServerDispatchProc macro calls ServerDispatch
  50. **    using uppServerDispatchProcInfo defined above.
  51. **
  52. **    Notes:
  53. **        ServerDispatch expects register D0 to always be 0 on input, so the
  54. **        dZero parameter (the first parameter) is always 0.
  55. **
  56. **        Not all versions of Macintosh File Sharing return a result in
  57. **        register D0, so we don't bother to get the value in D0. Instead, the
  58. **        SyncServerDispatch glue code (below) returns the result from the
  59. **        parameter block's ioResult field.
  60. */
  61. #define CallServerDispatchProc(userRoutine, thePB)        \
  62.         CallOSTrapUniversalProc((UniversalProcPtr)(userRoutine), uppServerDispatchProcInfo, _ServerDispatch, 0, (thePB))
  63.  
  64. /*****************************************************************************/
  65.  
  66. /*
  67. **    A concise version of TrapAvailable function.
  68. **    (another effort in the quest for smaller, faster code)
  69. */
  70. static    Boolean    TrapAvailable(short theTrap)
  71. {
  72.     TrapType tType;
  73.     short     numToolboxTraps;
  74.     
  75.     /* Get the trap type */
  76.     if ( (theTrap & 0x0800) > 0 )
  77.         tType = ToolTrap;
  78.     else
  79.         tType = OSTrap;
  80.     
  81.     /* If theTrap is ToolTrap, see if it is in the trap table */
  82.     if ( tType == ToolTrap )
  83.     {
  84.         /* Get the number of toolbox traps */
  85.         if ( NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap) )
  86.             numToolboxTraps = 0x200;
  87.         else
  88.             numToolboxTraps = 0x400;
  89.         
  90.         /* Is theTrap in the trap table? */
  91.         if ( (theTrap & 0x07ff) >= numToolboxTraps )
  92.             theTrap = _Unimplemented;    /* No, make it _Unimplemented */
  93.     }
  94.     
  95.     /* Trap is available if it doesn't equal _Unimplemented */
  96.     return ( NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap) );
  97. }
  98.  
  99. /*****************************************************************************/
  100.  
  101. /*
  102. **    SyncServerDispatch is the glue code to call the ServerDispatch trap
  103. **    from PowerPC code.
  104. */
  105. pascal OSErr ServerDispatchSync(SCParamBlockRec* PBPtr)
  106. {
  107.     /*
  108.     **    Keep the address of ServerDispatch in a static so we don't
  109.     **    have to check for ServerDispatch and get its address
  110.     **    every time SyncServerDispatch is called.
  111.     */
  112.     static ServerDispatchProcUPP serverDispatchAddress = NULL;
  113.     
  114.     /* If serverDispatchAddress is uninitialized, try to initialize it */
  115.     if ( serverDispatchAddress == NULL )
  116.     {
  117.         /* Make sure ServerDispatch is available (just in case someone didn't check for it first) */
  118.         if ( TrapAvailable(_ServerDispatch) )
  119.         {
  120.             /* Get the address of ServerDispatch */
  121.             serverDispatchAddress = (ServerDispatchProcUPP)NGetTrapAddress(_ServerDispatch, OSTrap);
  122.         }
  123.     }
  124.     
  125.     /* If serverDispatchAddress was initialized */ 
  126.     if ( serverDispatchAddress != NULL )
  127.     {
  128.         /* Call ServerDispatch and return the result from ioResult */
  129.         (void) CallServerDispatchProc(serverDispatchAddress, PBPtr);
  130.         return ( PBPtr->startParam.ioResult );
  131.     }
  132.     else
  133.     {
  134.         /* Return an error to indicate ServerDispatch wasn't available */
  135.         return ( paramErr );
  136.     }
  137. }
  138.  
  139. /*****************************************************************************/
  140.